package day09;

import java.util.Random;

public class TestString {
	public static void main(String[] args) {
		String s1 = new String("hello");
		System.out.println(s1);
		String s2 = new String("hello");
		System.out.println(s1==s2);
		System.out.println(s1.equals(s2));
		String s3 = "abc";
		String s4 = "abc";
		System.out.println(s3==s4);
		s3 = "abd";
		System.out.println(s4);
		System.out.println("===================");
		String str = "";
		long start = System.currentTimeMillis();
		for(int i=0; i<10000; i++){
			str = str + genericString();
		}
		long end = System.currentTimeMillis();
		System.out.println(end-start);
		StringBuffer sb = new StringBuffer();
		start = System.currentTimeMillis();
		for(int i=0; i<10000; i++){
			sb.append(genericString());
		}
		String str1 = sb.toString();
		end = System.currentTimeMillis();
		System.out.println(end-start);
		
		StringBuilder sb1 = new StringBuilder();
		start = System.currentTimeMillis();
		for(int i=0; i<10000; i++){
			sb1.append(genericString());
		}
		str1 = sb.toString();
		end = System.currentTimeMillis();
		System.out.println(end-start);
	}
	public void createString(){
		String s1 = new String("abc");
		String s2 = "def";
		String s3 = new String("def");
		String s4 = "abc"+"def"+"hij";
		String s5 = "hij";
	}
	public static String genericString(){
		Random r = new Random();
		int length = r.nextInt(9)+1;
		char[] cs = new char[length];
		for(int i=0; i<length; i++){
			char c = (char)('a' + r.nextInt(26));
			cs[i] = c;
		}
		return new String(cs);
	}
}









